//
//  XFRetweeteView.m
//  SinaBlog_OC
//
//  Created by macs on 15/11/17.
//  Copyright © 2015年 BlackTail. All rights reserved.
//

#import "XFRetweeteView.h"
#import "XFPictureView.h"

@interface XFRetweeteView ()
@property(nonatomic, weak) UILabel *textLable;
@property(nonatomic, weak) XFPictureView *pictureView;
@property(nonatomic, strong) MASConstraint *bottomContraint;
@end

@implementation XFRetweeteView

- (void)setRetweetes:(XFStatues *)retweetes {

  _retweetes = retweetes;

  self.textLable.text = retweetes.text;
  [self.bottomContraint uninstall];
  if (retweetes.pictureUrl.count != 0) {
    self.pictureView.picUrls = retweetes.pictureUrl;
    self.pictureView.hidden = NO;
    [self mas_updateConstraints:^(MASConstraintMaker *make) {
      self.bottomContraint = make.bottom.equalTo(self.pictureView.mas_bottom);
    }];
  } else {
    self.pictureView.hidden = YES;
    [self mas_updateConstraints:^(MASConstraintMaker *make) {
      self.bottomContraint = make.bottom.equalTo(self.textLable.mas_bottom);
    }];
  }
}

// 1.重写 init 方法

- (instancetype)initWithFrame:(CGRect)frame {

  if (self = [super initWithFrame:frame]) {
    [self setupUI];
    [self setupFrame];
  }
  return self;
}

// 2. setupUI添加子控件
- (void)setupUI {
  UILabel *lable = [[UILabel alloc] initWithTitle:@"转发微博"
                                            Color:[UIColor orangeColor]
                                             Font:14
                                           Margin:kStatueCellMargin];
  [self addSubview:lable];
  self.textLable = lable;

  XFPictureView *pictureView = [[XFPictureView alloc] init];
  [self addSubview:pictureView];
  self.pictureView = pictureView;
}

// 3. setupFrame添加子控件约束
- (void)setupFrame {
  [self.textLable mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.top.equalTo(self).offset(kStatueCellMargin);
  }];
  [self.pictureView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.equalTo(self.mas_left).offset(kStatueCellMargin);
    make.top.equalTo(self.textLable.mas_bottom).offset(kStatueCellMargin);
  }];
  [self mas_makeConstraints:^(MASConstraintMaker *make) {
    self.bottomContraint = make.bottom.equalTo(self.pictureView.mas_bottom);
  }];
}

@end
